//
//  Player.m
//  Pai9
//
//  Created by Zhou Tao on 10-4-19.
//  Copyright 2010 Free. All rights reserved.
//

#import "Player.h"

int cardCompare(int c1,int c2);
int intCompare(int i1,int i2);

@implementation Player

@synthesize card;
@synthesize dealer;
@synthesize AI;
@synthesize score;


-(void) sortCard
{
	int tmp;
	if(card == NULL)
	{
		return;		
	}
	for (int i=0; i<9; i++)
		for(int j=i+1;j<10;j++)
		{
			if(cardCompare(card[i],card[j]) < 0)
			   {
				   tmp = card[i];
				   card[i] = card[j];
				   card[j] = tmp;
			   }
		}
	//
}


			   
-(void) logOut
 {
	 for (int i=0; i<10; i++)
	{
		printf("%3d",card[i]);
	}			   
	 printf("\n");
 }
@end

#pragma mark PureC_Function

int cardCompare(int c1,int c2)
{
	if(c1 <13 && c2 < 13)
		return intCompare(c2,c1);	//红牌，ID越小，牌排列越大
	
	if(c1>=13 && c2>=13)	//黑牌，ID尾数越大，牌排列越大
	{
		return intCompare(c1%10,c2%10);
	}
	if(c1<13 && c2>=13) // 红与 黑
	{
		if(c2==13 || c2==16)
			return 1;
		return -intCompare(c1*2,21-2*(c2%10));
	}
	else 
	{
		if(c1==13 || c1== 16)
			return -1;
		return intCompare(c2*2,21-2*(c1%10));
	}
	return 0;
}
int intCompare(int i1,int i2)
{
	if(i1<i2)
		return -1;
	if(i1 == i2)
		return 0;
	return 1;
}